package books.ThinkingInJava.src.Chapter11;

import books.ThinkingInJava.src.Tools.Output;

import java.util.LinkedList;
import java.util.Scanner;

public class Stackm<Character> {
    private LinkedList<Character> storage = new LinkedList<Character>();

    public static void main(String[] args) {
        Stackm s = new Stackm();
        Scanner scan = new Scanner(System.in);
        if (scan.hasNext()) {
            String order = scan.next();
            char[] ch = order.toCharArray();
            int len = ch.length;
            for (int i = 0; i < len; i++) {
                if (ch[i] == '+') {
                    s.push(new java.lang.Character(ch[++i]));
                } else if (ch[i] == '-') {
                    s.pop();
                }
            }

            Output.println(s);
        }
    }

    public void push(Character c) {
        storage.add(c);
    }

    public Character peek() {
        return storage.getFirst();
    }

    public Character pop() {
        return storage.removeFirst();
    }

    public boolean isEmpty() {
        return storage.isEmpty();
    }

    @Override
    public String toString() {
        return storage.toString();
    }
}
